﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using TCG.Engine.Core;
using System.Threading;
using TCG.Engine;

namespace TCGWeb
{
    enum EventType
    {
        None,
        RequestMove
    }

    public sealed class WebPlayerInteraction: IPlayerInteraction
    {
        HttpSessionState Session;
        Match _tcgMatch = null;

        public Action InitializeMatch;

        public WebPlayerInteraction(HttpSessionState session)
        {
            Session = session;
        }

        public Match TCGMatch
        {
            get
            {
                if (_tcgMatch == null)
                {
                    _tcgMatch = Session["TCG_GAME"] as Match;
                    if (_tcgMatch == null)
                    {
                        Session["TCG_GAME"] = _tcgMatch = new Match();
                        InitializeMatch();
                        TCGMatch.NextRound();
                        TCGMatch.StartTurn();
                    }
                }
                return _tcgMatch;
            }
        }

        public Card DiscardCard()
        {
            throw new NotImplementedException();
        }

        public IEnumerable<Card> DiscardCards(int count)
        {
            return Enumerable.Range(0, count).Select(i => TCGMatch.ActivePlayer.Hand.ElementAt(i));
        }

        public void NotEnoughResources()
        {
            throw new NotImplementedException();
        }

        public int SelectGold()
        {
            throw new NotImplementedException();
        }

        public int SelectMana()
        {
            throw new NotImplementedException();
        }

        public Card Move(string cardId)
        {
            return String.IsNullOrEmpty(cardId) ? null : TCGMatch.ActivePlayer.HaveCard(cardId);
        }
    }
}